<!--
 * @Author: hucc
 * @Date: 2021-10-13 14:11:23
 * @LastEditors: hucc
 * @LastEditTime: 2021-10-13 14:24:10
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/vue.js"></script>
    <script src="../js/vue-router.js"></script>
</head>

<body>
    <div id="app">
        <!-- 4.路由的使用 -->
        <router-link to="/a">组件一</router-link>
        <router-link to="/b">组件二</router-link>
        <!-- 5.为组件加载提供容器窗口 -->
        <!-- router-view 实现了组件之间的动态加载 -->
        <router-view></router-view>
    </div>
    <script>
        //1.注册组件
        let com1 = {
            data() {
                return {

                }
            },
            template: `
              <div>
                组件一
                </div>
            `
        }
        let com2 = {
                data() {
                    return {

                    }
                },
                template: `
              <div>
                组件二
                </div>
            `
            }
            //2.定义路由
        let router = new VueRouter({
            routes: [{
                path: '/a',
                component: com1
            }, {
                path: '/b',
                component: com2
            }]
        })
        new Vue({
            el: '#app',
            data: {},
            methods: {},
            //3.路由注册
            router: router
        })
    </script>
</body>

</html>